set more off

*if needed, install packages
*ssc install ebalance 
*ssc install sutex2
*ssc install estout
*ssc install spost9_ado

* set working directory
cd ""

* import crossectional data
use datacross.dta, clear

* assign labels to variables
label variable frag_postMK1 "Insurgent Fragmentation"  
label variable frag_postMK1alt "Insurgent Fragmentation (alt.)"        
label variable frag "Insurgent Fragmentation (basic)"
label variable MKactive "State-led Coll. Targeting"
label variable frag_preMK1 "Prior Fragmentation" 
label variable frag_preMK1alt "Prior Fragmentation (alt.)" 
label variable irregular2 "Irregular War"
label variable rebsupnum "Ext. Rebel Support"
label variable excluded "Recr. from Excl. Groups"
label variable prevactive "Previously Active"
label variable fightcapnum "Fighting Capacity"
label variable terrcontnum "Territorial Control"
label variable e_v2x_neopat "Neopatrimonial Rule"
label variable dyadsfirstyear "Dyads at Conflict Onset"
label variable exclpop "Excl. Population"
label variable intensityfirstyear "Fighting Intensity"

*descriptive stats (see description in text)

tab MKactive frag_postMK1, row
tab MKactive frag_postMK1alt, row
tab MKactive frag, row

* appendix table 5
tab MKactive

* appendix table 6
tab frag_postMK1

* appendix table 7
sutex2 frag_postMK1 MKactive frag_preMK1 irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear, minmax varlabels


******* ENTROPY BALANCING 

* appendix table 8
ebalance MKactive frag_preMK1 irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear, tar(1) gen(_MKactive) keep(ebal1) replace


*with pweight 
reg frag_postMK1 MKactive [pweight=_MKactive], robust
estimates store m1ebal
reg frag_postMK1 MKactive [pweight=_MKactive], cluster(ccode)
estimates store m2ebal
reg frag_postMK1 MKactive frag_preMK1 [pweight=_MKactive], robust
estimates store m3ebal
reg frag_postMK1 MKactive frag_preMK1 [pweight=_MKactive], cluster(ccode)
estimates store m4ebal
reg frag_postMK1 MKactive frag_preMK1 irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear [pweight=_MKactive], robust
estimates store m5ebal
reg frag_postMK1 MKactive frag_preMK1 irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear [pweight=_MKactive], cluster(ccode)
estimates store m6ebal

logit frag_postMK1 MKactive [pweight=_MKactive], robust
estimates store m7ebal
logit frag_postMK1 MKactive [pweight=_MKactive], cluster(ccode)
estimates store m8ebal
logit frag_postMK1 MKactive frag_preMK1 [pweight=_MKactive], robust
estimates store m9ebal
logit frag_postMK1 MKactive frag_preMK1 [pweight=_MKactive], cluster(ccode)
estimates store m10ebal
logit frag_postMK1 MKactive frag_preMK1 irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear [pweight=_MKactive], robust
estimates store m11ebal

prchange MKactive, rest(median)
prvalue, x(MKactive=0) rest(median)
prvalue, x(MKactive=1) rest(median)

logit frag_postMK1 MKactive frag_preMK1 irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear [pweight=_MKactive], cluster(ccode)
estimates store m12ebal


* table 3 
#delimit ;
estout m1ebal m2ebal m3ebal m4ebal m5ebal m6ebal, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(r2 N_clust N, fmt(%9.3f %9.0f %9.0g) labels(R2 Clusters N)) 
label title(Probit Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lcccccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr

* appendix table 9
#delimit ;
estout m7ebal m8ebal m9ebal m10ebal m11ebal m12ebal, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(ll chi2 N_clust N, fmt(%9.3f %9.0g) labels(Log-Likelihood $\chi^{2}$ Clusters N)) 
label title(Probit Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lcccccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr


****** ENTROPY BALANCING WITH ALTERNATIVE PRIOR FRAGM VARIABLE


ebalance MKactive frag_preMK1alt irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear, tar(1) gen(_MKactivealt) keep(ebal2) replace


*with pweight
reg frag_postMK1alt MKactive [pweight=_MKactivealt], robust
estimates store m1ebalalt
reg frag_postMK1alt MKactive [pweight=_MKactivealt], cluster(ccode)
estimates store m2ebalalt

reg frag_postMK1alt MKactive frag_preMK1alt [pweight=_MKactivealt], robust
estimates store m3ebalalt
reg frag_postMK1alt MKactive frag_preMK1alt [pweight=_MKactivealt], cluster(ccode)
estimates store m4ebalalt
reg frag_postMK1alt MKactive frag_preMK1alt irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear [pweight=_MKactivealt], robust
estimates store m5ebalalt
reg frag_postMK1alt MKactive frag_preMK1alt irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear [pweight=_MKactivealt], cluster(ccode)
estimates store m6ebalalt


logit frag_postMK1alt MKactive [pweight=_MKactivealt], robust
estimates store m7ebalalt
logit frag_postMK1alt MKactive [pweight=_MKactivealt], cluster(ccode)
estimates store m8ebalalt


logit frag_postMK1alt MKactive frag_preMK1alt [pweight=_MKactivealt], robust
estimates store m9ebalalt
logit frag_postMK1alt MKactive frag_preMK1alt [pweight=_MKactivealt], cluster(ccode)
estimates store m10ebalalt
logit frag_postMK1alt MKactive frag_preMK1alt irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear [pweight=_MKactivealt], robust
estimates store m11ebalalt

prchange MKactive, rest(median)
prvalue, x(MKactive=0) rest(median)
prvalue, x(MKactive=1) rest(median)

logit frag_postMK1alt MKactive frag_preMK1alt irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear [pweight=_MKactivealt], cluster(ccode)
estimates store m12ebalalt


* appendix table 10
#delimit ;
estout m1ebalalt m2ebalalt m3ebalalt m4ebalalt m5ebalalt m6ebalalt, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(r2 N_clust N, fmt(%9.3f %9.0f %9.0g) labels(R2 Clusters N)) 
label title(Probit Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lcccccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr

* appendix table 11
#delimit ;
estout m7ebalalt m8ebalalt m9ebalalt m10ebalalt m11ebalalt m12ebalalt, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(ll chi2 N_clust N, fmt(%9.3f %9.0g) labels(Log-Likelihood $\chi^{2}$ Clusters N)) 
label title(Probit Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lcccccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr



*********** NO ENTROPY BALANCING 


*OLS
reg frag_postMK1 MKactive, robust
estimates store m1
reg frag_postMK1 MKactive, cluster(ccode)
estimates store m2
reg frag_postMK1 MKactive frag_preMK1, robust
estimates store m3
reg frag_postMK1 MKactive frag_preMK1, cluster(ccode)
estimates store m4
reg frag_postMK1 MKactive frag_preMK1 irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear, robust
estimates store m5
reg frag_postMK1 MKactive frag_preMK1 irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear, cluster(ccode)
estimates store m6

*Logit
logit frag_postMK1 MKactive, robust
estimates store m7
logit frag_postMK1 MKactive, cluster(ccode)
estimates store m8
logit frag_postMK1 MKactive frag_preMK1, robust
estimates store m9
logit frag_postMK1 MKactive frag_preMK1, cluster(ccode)
estimates store m10
logit frag_postMK1 MKactive frag_preMK1 irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear, robust
estimates store m11

prchange MKactive, rest(median)
prvalue, x(MKactive=0) rest(median)
prvalue, x(MKactive=1) rest(median) 

logit frag_postMK1 MKactive frag_preMK1 irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear, cluster(ccode)
estimates store m12


******* NO ENTROPY BALANCING W/ ALTERNATIVE PRIOR FRAGMENTATION VARIABLE

reg frag_postMK1alt MKactive, robust
estimates store m1alt
reg frag_postMK1alt MKactive, cluster(ccode)
estimates store m2alt
reg frag_postMK1alt MKactive frag_preMK1alt, robust
estimates store m3alt
reg frag_postMK1alt MKactive frag_preMK1alt, cluster(ccode)
estimates store m4alt
reg frag_postMK1alt MKactive frag_preMK1alt irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear, robust
estimates store m5alt
reg frag_postMK1alt MKactive frag_preMK1alt irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear, cluster(ccode)
estimates store m6alt 


logit frag_postMK1alt MKactive, robust
estimates store m7alt
logit frag_postMK1alt MKactive, cluster(ccode)
estimates store m8alt
logit frag_postMK1alt MKactive frag_preMK1alt, robust
estimates store m9alt
logit frag_postMK1alt MKactive frag_preMK1alt, cluster(ccode)
estimates store m10alt
logit frag_postMK1alt MKactive frag_preMK1alt irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear, robust
estimates store m11alt
logit frag_postMK1alt MKactive frag_preMK1alt irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear, cluster(ccode)
estimates store m12alt
logit frag_postMK1 MKactive frag_preMK1alt irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear, cluster(ccode)
estimates store m12alt

* appendix table 12
#delimit ;
estout m1 m2 m3 m4 m5 m6, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(r2 N_clust N, fmt(%9.3f %9.0f %9.0g) labels(R2 Clusters N)) 
label title(Probit Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lcccccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr

* appendix table 13
#delimit ;
estout m7 m8 m9 m10 m11 m12, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(ll chi2 N_clust N, fmt(%9.3f %9.0g) labels(Log-Likelihood $\chi^{2}$ Clusters N)) 
label title(Probit Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lcccccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr


*appendix table 14
#delimit ;
estout m1alt m2alt m3alt m4alt m5alt m6alt, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(r2 N_clust N, fmt(%9.3f %9.0f %9.0g) labels(R2 Clusters N)) 
label title(Probit Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lcccccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr


*appendix table 15
#delimit ;
estout m7alt m8alt m9alt m10alt m11alt m12alt, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(ll chi2 N_clust N, fmt(%9.3f %9.0g) labels(Log-Likelihood $\chi^{2}$ Clusters N)) 
label title(Probit Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lcccccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr


****** ENTROPY BALANCING W/ BASIC DV

ebalance MKactive irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear, tar(1) gen(_MKactivebasic) keep(ebal1) replace


*with pweight 
reg frag MKactive [pweight=_MKactivebasic], robust
estimates store m1ebalbasic
reg frag MKactive [pweight=_MKactivebasic], cluster(ccode)
estimates store m2ebalbasic
reg frag MKactive [pweight=_MKactivebasic], robust
estimates store m3ebalbasic
reg frag  MKactive [pweight=_MKactivebasic], cluster(ccode)
estimates store m4ebalbasic
reg frag MKactive irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear [pweight=_MKactivebasic], robust
estimates store m5ebalbasic
reg frag  MKactive irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear [pweight=_MKactivebasic], cluster(ccode)
estimates store m6ebalbasic

logit frag MKactive [pweight=_MKactivebasic], robust
estimates store m7ebalbasic
logit frag  MKactive [pweight=_MKactivebasic], cluster(ccode)
estimates store m8ebalbasic
logit frag  MKactive [pweight=_MKactivebasic], robust
estimates store m9ebalbasic
logit frag  MKactive [pweight=_MKactivebasic], cluster(ccode)
estimates store m10ebalbasic
logit frag  MKactive irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear [pweight=_MKactivebasic], robust
estimates store m11ebalbasic
logit frag MKactive irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear [pweight=_MKactivebasic], cluster(ccode)
estimates store m12ebalbasic



****** NO ENTROPY BALANCING W/ BASIC DV

*OLS
reg frag  MKactive, robust
estimates store m1basic
reg frag  MKactive, cluster(ccode)
estimates store m2basic
reg frag  MKactive, robust
estimates store m3basic
reg frag  MKactive, cluster(ccode)
estimates store m4basic
reg frag  MKactive irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear, robust
estimates store m5basic
reg frag  MKactive irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear, cluster(ccode)
estimates store m6basic

*Logit
logit frag  MKactive, robust
estimates store m7basic
logit frag  MKactive, cluster(ccode)
estimates store m8basic
logit frag  MKactive, robust
estimates store m9basic
logit frag  MKactive, cluster(ccode)
estimates store m10basic
logit frag  MKactive irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear, robust
estimates store m11basic
logit frag MKactive irregular2 rebsupnum excluded prevactive fightcapnum terrcontnum e_v2x_neopat dyadsfirstyear exclpop intensityfirstyear, cluster(ccode)
estimates store m12basic



* appendix table 16
#delimit ;
estout m1ebalbasic m2ebalbasic m3ebalbasic m4ebalbasic m5ebalbasic m6ebalbasic, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(r2 N_clust N, fmt(%9.3f %9.0f %9.0g) labels(R2 Clusters N)) 
label title(Probit Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lcccccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr

* appendix table 17
#delimit ;
estout m7ebalbasic m8ebalbasic m9ebalbasic m10ebalbasic m11ebalbasic m12ebalbasic, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(ll chi2 N_clust N, fmt(%9.3f %9.0g) labels(Log-Likelihood $\chi^{2}$ Clusters N)) 
label title(Probit Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lcccccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr

* appendix table 18
#delimit ;
estout m1basic m2basic m3basic m4basic m5basic m6basic, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(r2 N_clust N, fmt(%9.3f %9.0f %9.0g) labels(R2 Clusters N)) 
label title(Probit Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lcccccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr

* appendix table 19
#delimit ;
estout m7basic m8basic m9basic m10basic m11basic m12basic, starlevels(+ .10 * 0.05 ** 0.01 *** 0.001) cells(b(star fmt(%9.3f)) se(par)) stats(ll chi2 N_clust N, fmt(%9.3f %9.0g) labels(Log-Likelihood $\chi^{2}$ Clusters N)) 
label title(Probit Estimates)  collabels(, none) varlabels(_cons Constant) style(tex)prehead("\begin{tabular}{lcccccc}" \hline\hline) 
posthead(\hline) prefoot(\hline) postfoot(\hline\hline "\end{tabular}");
#delimit cr